#include "SphereGeode.h"

SphereGeode::SphereGeode(): osg::Geode()
{
    m_radius = 1.0;
    m_fineness = 1;
    buildChildNode();

}

SphereGeode::~SphereGeode()
{

}

double SphereGeode::getRadius()
{
    return m_radius;

}

double SphereGeode::getFineness()
{
    return m_fineness;

}

void SphereGeode::setRadius(double radius)
{
    m_radius = radius;
    m_sphere->setRadius(m_radius);
    m_shpereShapeDrawable->dirtyDisplayList();
    m_shpereShapeDrawable->dirtyBound();

}

void SphereGeode::setFineness(double fineness)
{
    m_fineness = fineness;
    m_shpereShapeDrawable->getTessellationHints()->setDetailRatio(m_fineness);
    m_shpereShapeDrawable->dirtyDisplayList();
    m_shpereShapeDrawable->dirtyBound();

}

void SphereGeode::buildChildNode()
{
    //add a shpere
    osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints;
    hints->setDetailRatio(m_fineness);

    m_sphere = new osg::Sphere(osg::Vec3(0.0,0.0,0.0), m_radius);
    m_shpereShapeDrawable = new osg::ShapeDrawable(m_sphere, hints);
    this->addDrawable(m_shpereShapeDrawable);
}
